package com.guyj.baseapp.demo.bgazxing;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.guyj.baseapp.R;
import com.guyj.common.base.BaseActivity;
import com.guyj.common.utils.ImageUtils;
import com.guyj.common.utils.QRCodeUtils;

import butterknife.Bind;
import butterknife.OnClick;

public class BgaZxingActivity extends BaseActivity {

    @Bind(R.id.iv_zxing)
    ImageView ivZxing;

    @Override
    public int getContentViewId() {
        return R.layout.activity_bga_zxing;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setBack();
        setTitle("bga的zxing");
    }

    @Override
    protected void initVariable() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }
    @OnClick({R.id.tv_generate_pic, R.id.tv_scan_pic})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_generate_pic:
                Bitmap logo= null;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                    logo = ImageUtils.drawableToBitmap(getResources().getDrawable(R.mipmap.ic_launcher,null));
                }else {
                    logo = ImageUtils.drawableToBitmap(getResources().getDrawable(R.mipmap.ic_launcher));
                }
                QRCodeUtils.createImage("中英文混合二维码zxing内容", 300, 300, logo, new QRCodeUtils.QRCodeCreateListener(){
                    @Override
                    public void onCreateSuccess(Bitmap bitmap) {
                        ivZxing.setImageBitmap(bitmap);
                    }
                });

                break;
            case R.id.tv_scan_pic:
                Intent openCameraIntent = new Intent(context,BgaScanActivity.class);
                startActivityForResult(openCameraIntent, 0);
                break;
        }
    }

}
